import axios from 'axios'
import { Toast } from 'vant'

const baseURL = process.env.NODE_ENV === 'development' ? '/douban' : ''
const service = axios.create({
  baseURL,
  timeout: 3000,
  withCredentials: true,
})

service.interceptors.request.use(config => {
  Toast.loading({
    message: '加载中...',
    duration: 0,
  })
  return config
})

service.interceptors.response.use(response => {
  Toast.clear()
  if (response.status >= 200 && response.status < 300) {
    return response.data
  }
  const err = new Error('请求出现异常')
  err.error = response
  return Promise.reject(err)
})
export default service
